let person = {
  name: "marry",
  age: 22
}
/* Proxy 一次性监听整个对象*/
person = new Proxy(person, {
  get() { },
  set() { }
})
/* Object.defineProperty */
// Object.keys(person).forEach(key => {
//   Object.defineProperty(person, key, {
//     set() { },
//     get() { }
//   })
// })
// Object.defineProperty不生效
person.newkey = '我是新加的属性'

console.log(person.newkey
)

var obj = new Proxy({}, {
  get: function (target, propKey, receiver) {
    console.log(`getting ${propKey}!`);
    console.log(target, propKey, receiver)
    return Reflect.get(target, propKey, receiver);
  },
  set: function (target, propKey, value, receiver) {
    console.log(`setting ${propKey}!`);
    console.log(target, propKey, value, receiver)
    return Reflect.set(target, propKey, value, receiver);
  },
  preventExtensions: function (target) {
    console.log('called');
    Object.preventExtensions(target);
    return true;
  }
});
Object.preventExtensions(obj)
obj.a = 1